package org.phoenixframework.common.entity.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.phoenixframework.common.tools.JacksonUtil;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.LocalDateTime;

/**
 * Created by IntelliJ IDEA.
 *
 * @author doublelifeke
 * Email: hautxxxyzjk@163.com
 * DateTime: 2020/12/22 21:42
 * Description:
 * 乐观锁：https://mp.baomidou.com/guide/interceptor-optimistic-locker.html#optimisticlockerinnerinterceptor
 */
@Data
@ApiModel(value = "父类")
public class BaseEntity {


    @ApiModelProperty(value = "版本号")
    @TableField(value = "version")
    @Version
    private Long version;

    @ApiModelProperty(value = "逻辑删除，0默认，1删除")
    @TableField(value = "del_flag")
    @TableLogic
    private Integer delFlag;

    @ApiModelProperty(value = "审计字段：创建人")
    @TableField(value = "created_by", fill = FieldFill.INSERT)
    private Long createdBy;

    @JsonSerialize(using = JacksonUtil.JsonLocalDateTimeSerializer.class)
    @JsonDeserialize(using = JacksonUtil.JsonLocalDateTimeDeserializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "审计字段：创建时间")
    @TableField(value = "created_date", fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createdDate;

    @ApiModelProperty(value = "审计字段：最后修改人")
    @TableField(value = "last_modified_by", fill = FieldFill.INSERT_UPDATE)
    private Long lastModifiedBy;

    @JsonSerialize(using = JacksonUtil.JsonLocalDateTimeSerializer.class)
    @JsonDeserialize(using = JacksonUtil.JsonLocalDateTimeDeserializer.class)
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "审计字段：最后修改时间")
    @TableField(value = "last_modified_date", fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastModifiedDate;

}
